package com.chendx.store.order.controller;

import com.chendx.model.cart.dto.CartDto;
import com.chendx.model.common.dtos.ResponseResult;
import com.chendx.store.api.cart.CartControllerApi;
import com.chendx.store.order.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Created by chendx on 2022/4/19.
 */
@RestController
@RequestMapping("/api/cart")
public class CartController implements CartControllerApi {

    @Autowired
    private CartService cartService;

    @Override
    @PostMapping("/add")
    public ResponseResult addCart(@RequestBody CartDto dto) {
        return cartService.addCart(dto);
    }

    @Override
    @GetMapping("/loadCart")
    public ResponseResult loadCart() {
        return cartService.loadCart();
    }

    @Override
    @PostMapping("/updateChecked")
    public ResponseResult updateChecked(@RequestBody CartDto dto) {
        return cartService.updateChecked(dto);
    }

    @Override
    @GetMapping("/deleteChecked")
    public ResponseResult deleteChecked() {
        return cartService.deleteChecked();
    }

    @Override
    @GetMapping("/preferential")
    public ResponseResult preferential(Integer totalMoney) {
        return cartService.preferential(totalMoney);
    }

    @Override
    @GetMapping("/orderPref")
    public ResponseResult orderPref(Integer totalMoney, Integer categoryId) {
        return cartService.orderPref(totalMoney,categoryId);
    }

    @Override
    @GetMapping("/loadCartList")
    public ResponseResult loadCheckedCartList() {
        return cartService.loadCheckedCartList();
    }

}
